from rest_framework import status as s
from rest_framework.response import Response


class BaseResponse(Response):

    def __init__(self, data=None, status=None, template_name=None, headers=None, exception=False,
                 content_type=None):
        super().__init__(data, status, template_name, headers, exception, content_type)
        self.data = {
            'status': self.status_code,
            'msg': "null",
            'data': self.data
        }

    def success(self, message="success"):
        self.data["msg"] = message
        if self.status_code is None:
            self.data["status"] = s.HTTP_200_OK
        return self

    def fail(self, message="fail"):
        self.data["msg"] = message
        if self.status_code is None:
            self.data["status"] = s.HTTP_400_BAD_REQUEST

        if self.data["data"] is not None:
            self.data["msg"] = str(self.data["data"])

        return self
